package com.situ.company.init;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@WebFilter("/web/page/*")
public class UserFilter implements Filter {
	//防盗链
	
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
			throws IOException, ServletException {
		//session.setAttribute("user",user);
		HttpServletRequest request = (HttpServletRequest) req;
		HttpSession session = request.getSession();
		Object user = session.getAttribute("user");
		if (user == null) {
			req.getRequestDispatcher("/web/login.jsp").forward(request, resp);
			//跳转页面
			//request.getRequestDispatcher("").forward(request,resp);//请求转发
			//((HttpServletResponse) resp).sendRedirect("");//请求重定向
		}else {
			chain.doFilter(req, resp);//放行
		}
	}
	
}
